package cn.yours.web.controller;

import org.springframework.web.bind.annotation.*;
import java.io.FileWriter;
import java.io.IOException;

@RestController
public class SaveController {

    @PostMapping("/save")
    public String saveContent(@RequestBody ContentRequest contentRequest) {
        String filePath = "F:/file_location/TinyMCE5/" + contentRequest.getFilename();
        System.out.println("触发文件");
        try (FileWriter fileWriter = new FileWriter(filePath)) {
            fileWriter.write(contentRequest.getContent());
        } catch (IOException e) {
            e.printStackTrace();
            return "文件上传失败";
        }

        return "文件上传成功";
    }

    public static class ContentRequest {
        private String content;
        private String filename;

        public String getContent() {
            return content;
        }

        public void setContent(String content) {
            this.content = content;
        }

        public String getFilename() {
            return filename;
        }

        public void setFilename(String filename) {
            this.filename = filename;
        }
    }
}
